package com.demo.convert;

import com.demo.convert.exception.Html2PdfException;
import com.demo.convert.exception.Word2HtmlException;
import com.demo.convert.html2pdf.Html2PdfConverter;
import com.demo.convert.word2html.office2007.Word2HtmlConverter;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author fenggang.li
 * @create 2019-09-12 12:52
 */
@Slf4j
public class StagingApplication {

    public static void main(String[] args) throws Word2HtmlException, Html2PdfException {
        // word
        String resourcesFolder = BuildOutputFolderAssistant.getDistFolder("resources/main");
        String wordFilePath = resourcesFolder + "/word2007/sample.docx";
        log.info("Word file is {}", wordFilePath);

        // dist folder
        SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
        String timestamp = timestampFormat.format(new Date());
        String distFolder = BuildOutputFolderAssistant.getDistFolder("test_cases/" + timestamp);
        log.info("Dist folder is {}", distFolder);
        new File(distFolder).mkdirs();

        // html
        String htmlFilePath = distFolder + "sample.html";
        log.info("Html file is {}", htmlFilePath);
        String imageRelativePath = "image";
        String imagePath = distFolder + imageRelativePath;
        log.info("Image folder is {}", imagePath);
        new File(imagePath).mkdirs();

        // pdf
        String pdfFilePath = distFolder + "sample.pdf";
        log.info("Pdf file is {}", pdfFilePath);

        Word2HtmlConverter.convert(wordFilePath, htmlFilePath, imagePath, imageRelativePath);

        Html2PdfConverter.convert(htmlFilePath, pdfFilePath);

    }
}
